package algorithms.tree;

/**
 * @author lizen
 */
public class TestBinaryTree {
    public static void test() {
        BinaryTree tree = new BinaryTree();

        // 插入节点
        tree.insert(5);
        tree.insert(3);
        tree.insert(7);
        tree.insert(2);
        tree.insert(4);
        tree.insert(6);
        tree.insert(8);

        // 遍历
        System.out.print("前序遍历: ");
        tree.preOrderTraversal();
        System.out.println();

        System.out.print("中序遍历: ");
        tree.inOrderTraversal();
        System.out.println();

        System.out.print("后序遍历: ");
        tree.postOrderTraversal();
        System.out.println();

        System.out.print("层序遍历: ");
        tree.levelOrderTraversal();
        System.out.println();

        // 查找
        System.out.println("查找 4: " + tree.contains(4));
        System.out.println("查找 9: " + tree.contains(9));

        // 高度
        System.out.println("树的高度: " + tree.getHeight());

        // 删除
        tree.delete(3);
        System.out.print("删除3后中序遍历: ");
        tree.inOrderTraversal();
    }
}
